package model;
import java.awt.Color;
/**
 * This class mimics a box in the prescription and then
 * can be saved with all it information in the prescription
 * class in an array list.
 * This class will just house the dimensions and location of the box,
 * along with some functions that perform basic operations such
 * as check if the box is being dragged, add lines of text, and
 * check whether a certain coordinate is within this box's dimensions.
 * 
 * @author Mohammad Abdullah
 * @version 1.0
 * 
 */
public class PrescriptionBox extends PrescriptionObject{
	private int height;
	private int width;
	private boolean isResizing;	private String placeholder;
	/**
	 * Constructor to create a new box object.
	 * 
	 * @param x - x coordinate of the box object
	 * @param y - y coordinate of the box object
	 * @param height - height of box object
	 * @param width - width of box
	 * 
	 */
	public PrescriptionBox(
			int x,
			int y, 
			int height, 
			int width, 
			Color lineColour,
			Color fillColour,
			Color textColour,
			float lineWidth,
			String name,
			boolean isTransparent){
		super(x, y, lineColour, lineWidth, fillColour, textColour);
		this.height = height;
		this.width = width;
		super.setName(name);		this.placeholder = "";
		isResizing = false;
		
		updateResizePoints();
	}	//TODO: fix new box creation so boxes don't overlap.		/**	 * Default construction of a prescription box object	 */
	public PrescriptionBox(){
		this(Constants.DEFAULT_X, 
				Constants.DEFAULT_Y, 
				Constants.DEFAULT_HEIGHT,
				Constants.DEFAULT_WIDTH,
				Constants.DEFAULT_LINE_COLOUR,
				Constants.DEFAULT_FILL_COLOUR,
				Constants.DEFAULT_TEXT_COLOUR,
				Constants.DEFAULT_LINE_WIDTH,
				"",
				false);	
	}	/**	 * Set the name for this objects place holder	 * @param newPlaceholder	 */	public void setPlaceholder(String newPlaceholder){		this.placeholder = newPlaceholder;	}		/**	 * Returns the place holder for this object	 * @return 	 */	public String getPlaceholder(){		return this.placeholder;	}
	/**
	 * Updates the resize square coordinates according to objects dimensions
	 */
	public void updateResizePoints(){
		this.resizeX = (getX() + getWidth()) + 1;
		this.resizeY = (getY() + getHeight()) + 1;
	}
	/**
	 * Sets the height of the box
	 * @param height height of box object
	 */
	public void setHeight(int height){
		this.height = height;
		updateResizePoints();
	}
	/**
	 * Gets the height of the box
	 * @return the height of box object
	 */
	public int getHeight(){
		return height;
	}
	/**
	 * Sets the width of the box object
	 * @param width width of box object
	 */
	public void setWidth(int width){
		this.width = width;
		updateResizePoints();
	}
	/**
	 * Gets the width of the box object
	 * @return the width of box object
	 */
	public int getWidth(){
		return width;
	}

	/**
	 * Sets whether a box can be resized
	 * @param resize if the box is being resized this is set to true
	 */
	public void setResize(boolean resize){
		isResizing = resize;
	}
	/**
	 * Checks whether a box object can be resized
	 * @return if the box can resize, returns true, if not, returns false
	 */
	public boolean isResizing(){
		return isResizing;
	}
	
	/**
	 * Checks the bounds of this box 
	 * @param x - x coordinate of point to be checked
	 * @param y - y coordinate of point to be checked
	 * @return true - if the point is inside the box
	 */
	public boolean checkBounds(int x, int y){
		if(x >= (this.x - 4) 
				&& x <= (this.x + this.width + 4) 
				&& y >= (this.y - 4)
				&& y <= (this.y + this.height + 4)){
			return true;
		}
		return false;
	}
}